home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 10868 / 10868.xpi / chrome / sync.jar / content / generic-change.js < prev    next >
Text File  |  2010-02-02  |  9KB  |  242 lines

  1. var Ci = Components.interfaces;
  2. var Cc = Components.classes;
  3. var Cr = Components.results;
  4.  
  5. let Change = {
  6.   __os: null,
  7.   get _os() {
  8.     if (!this.__os)
  9.       this.__os = Cc["@mozilla.org/observer-service;1"]
  10.         .getService(Ci.nsIObserverService);
  11.     return this.__os;
  12.   },
  13.  
  14.   get _stringBundle() {
  15.     let stringBundle = document.getElementById("weaveStringBundle");
  16.     this.__defineGetter__("_stringBundle", function() { return stringBundle; });
  17.     return this._stringBundle;
  18.   },
  19.  
  20.   get _dialog() {
  21.     delete this._dialog;
  22.     return this._dialog = document.getElementById("change-dialog");
  23.   },
  24.  
  25.   get _title() {
  26.     delete this._title;
  27.     return this._title = document.getElementById("mainTitle");
  28.   },
  29.  
  30.   get _status() {
  31.     delete this._status;
  32.     return this._status = document.getElementById("mainStatus");
  33.   },
  34.  
  35.   get _statusIcon() {
  36.     delete this._statusIcon;
  37.     return this._statusIcon = document.getElementById("mainStatusIcon");
  38.   },
  39.  
  40.   get _oldBoxRow() {
  41.     delete this._oldBoxRow;
  42.     return this._oldBoxRow = document.getElementById("oldBoxRow");
  43.   },
  44.  
  45.   get _currentBox() {
  46.     delete this._currentBox;
  47.     return this._currentBox = document.getElementById("currentBoxText");
  48.   },
  49.  
  50.   get _firstBox() {
  51.     delete this._firstBox;
  52.     return this._firstBox = document.getElementById("textBox1");
  53.   },
  54.  
  55.   get _secondBox() {
  56.     delete this._secondBox;
  57.     return this._secondBox = document.getElementById("textBox2");
  58.   },
  59.   
  60.   get _currentPasswordInvalid() {
  61.     return Weave.Status.login == Weave.LOGIN_FAILED_LOGIN_REJECTED;
  62.   },
  63.  
  64.   get _currentPassphraseInvalid() {
  65.     return Weave.Status.login == Weave.LOGIN_FAILED_INVALID_PASSPHRASE;
  66.   },
  67.  
  68.   onLoad: function Change_onLoad() {
  69.     /* Load labels */
  70.     let cboxlabel = document.getElementById("currentBoxLabel");
  71.     let box1label = document.getElementById("textBox1Label");
  72.     let box2label = document.getElementById("textBox2Label");
  73.  
  74.     switch (Weave.Utils._genericDialogType) {
  75.       case "ResetPassphrase":
  76.         this._title.value = this._str("reset.passphrase.title");
  77.         box1label.value = this._str("new.passphrase.label");
  78.         box2label.value = this._str("new.passphrase.confirm");
  79.         this._dialog.setAttribute(
  80.           "ondialogaccept",
  81.           "return Change.doResetPassphrase();"
  82.         );
  83.         break;
  84.       case "ChangePassphrase":
  85.         this._title.value = this._str("change.passphrase.title");
  86.         cboxlabel.value = this._str("new.passphrase.old");
  87.         box1label.value = this._str("new.passphrase.label");
  88.         box2label.value = this._str("new.passphrase.confirm");
  89.         this._dialog.setAttribute(
  90.           "ondialogaccept",
  91.           "return Change.doChangePassphrase();"
  92.         );
  93.         this._oldBoxRow.setAttribute("hidden", this._currentPassphraseInvalid);
  94.         break;
  95.       case "ChangePassword":
  96.         this._title.value = this._str("change.password.title");
  97.         cboxlabel.value = this._str("new.password.old");
  98.         box1label.value = this._str("new.password.label");
  99.         box2label.value = this._str("new.password.confirm");
  100.         this._dialog.setAttribute(
  101.           "ondialogaccept",
  102.           "return Change.doChangePassword();"
  103.         );
  104.         this._oldBoxRow.setAttribute("hidden", this._currentPasswordInvalid);
  105.         break;
  106.     }
  107.     this._os.addObserver(this, "weave:service:changepwd:start", false);
  108.     this._os.addObserver(this, "weave:service:changepwd:error", false);
  109.     this._os.addObserver(this, "weave:service:changepwd:finish", false);
  110.     this._os.addObserver(this, "weave:service:changepph:start", false);
  111.     this._os.addObserver(this, "weave:service:changepph:error", false);
  112.     this._os.addObserver(this, "weave:service:changepph:finish", false);
  113.     this._os.addObserver(this, "weave:service:resetpph:start", false);
  114.     this._os.addObserver(this, "weave:service:resetpph:error", false);
  115.     this._os.addObserver(this, "weave:service:resetpph:finish", false);
  116.   },
  117.  
  118.   shutDown: function Change_shutDown() {
  119.     this._os.removeObserver(this, "weave:service:changepwd:start", false);
  120.     this._os.removeObserver(this, "weave:service:changepwd:error", false);
  121.     this._os.removeObserver(this, "weave:service:changepwd:finish", false);
  122.     this._os.removeObserver(this, "weave:service:changepph:start", false);
  123.     this._os.removeObserver(this, "weave:service:changepph:error", false);
  124.     this._os.removeObserver(this, "weave:service:changepph:finish", false);
  125.     this._os.removeObserver(this, "weave:service:resetpph:start", false);
  126.     this._os.removeObserver(this, "weave:service:resetpph:error", false);
  127.     this._os.removeObserver(this, "weave:service:resetpph:finish", false);
  128.   },
  129.  
  130.   observe: function Change_observer(subject, topic, data) {
  131.     switch (topic) {
  132.       case "weave:service:resetpph:start":
  133.       case "weave:service:changepwd:start":
  134.       case "weave:service:changepph:start":
  135.         this._statusIcon.setAttribute("status", "active");
  136.         this._status.style.color = "-moz-dialogtext";
  137.         this._dialog.getButton("cancel").setAttribute("disabled", "true");
  138.         this._dialog.getButton("accept").setAttribute("disabled", "true");
  139.         break;
  140.       case "weave:service:resetpph:error":
  141.       case "weave:service:changepwd:error":
  142.       case "weave:service:changepph:error":
  143.         this._statusIcon.setAttribute("status", "error");
  144.         this._status.style.color = "-moz-dialogtext";
  145.         this._dialog.getButton("cancel").setAttribute("disabled", "false");
  146.         this._dialog.getButton("accept").setAttribute("disabled", "false");
  147.         break;
  148.       case "weave:service:resetpph:finish":
  149.       case "weave:service:changepwd:finish":
  150.       case "weave:service:changepph:finish":
  151.         this._statusIcon.setAttribute("status", "success");
  152.         this._status.style.color = "-moz-dialogtext";
  153.         this._dialog.getButton("cancel").setAttribute("disabled", "true");
  154.         this._dialog.getButton("accept").setAttribute("disabled", "true");
  155.         window.setTimeout(window.close, 1500);
  156.         break;
  157.     }
  158.   },
  159.  
  160.   doResetPassphrase: function Change_doResetPassphrase() {
  161.     if (!this._firstBox.value || !this._secondBox.value)
  162.       alert(this._str("noPassphrase.alert"));
  163.     else if (this._firstBox.value != this._secondBox.value)
  164.       alert(this._str("passphraseNoMatch.alert"));
  165.     else {
  166.       this._status.value = this._str("reset.passphrase.label");
  167.  
  168.       if (Weave.Service.resetPassphrase(this._firstBox.value)) {
  169.         this._status.value = this._str("reset.passphrase.success");
  170.         this._loginDialog.cancelDialog();
  171.       }
  172.       else
  173.         this._status.value = this._str("reset.passphrase.error");
  174.     }
  175.  
  176.     return false;
  177.   },
  178.  
  179.   doChangePassphrase: function Change_doChangePassphrase() {
  180.     if (!this._firstBox.value || !this._secondBox.value)
  181.       alert(this._str("noPassphrase.alert"));
  182.     else if (this._firstBox.value != this._secondBox.value)
  183.       alert(this._str("passphraseNoMatch.alert"));
  184.     else if (this._currentPassphraseInvalid) {
  185.       Weave.Service.passphrase = this._firstBox.value;
  186.       Weave.Service.persistLogin();
  187.       Weave.Service.login();
  188.       window.setTimeout(window.close, 1500);
  189.       this._status.value = this._str("change.passphrase.success");
  190.     }
  191.     else if (this._currentBox.value != Weave.Service.passphrase)
  192.       alert(this._str("incorrectPassphrase.alert"));
  193.     else {
  194.       this._status.value = this._str("change.passphrase.label");
  195.  
  196.       if (Weave.Service.changePassphrase(this._firstBox.value))
  197.         this._status.value = this._str("change.passphrase.success");
  198.       else
  199.         this._status.value = this._str("change.passphrase.error");
  200.     }
  201.  
  202.     return false;
  203.   },
  204.  
  205.   doChangePassword: function Change_doChangePassword() {
  206.     if (!this._firstBox.value || !this._secondBox.value)
  207.       alert(this._str("noPassword.alert"));
  208.     else if (this._firstBox.value != this._secondBox.value)
  209.       alert(this._str("passwordNoMatch.alert"));
  210.     else if (this._firstBox.value == Weave.Service.username)
  211.       alert(this._str("change.password.status.passwordSameAsUsername" ));
  212.     else if (this._firstBox.value == Weave.Service.passphrase)
  213.       alert(this._str("change.password.status.passwordSameAsPassphrase"));
  214.     else if (this._currentPasswordInvalid) {
  215.       Weave.Service.password = this._firstBox.value;
  216.       Weave.Service.persistLogin();
  217.       Weave.Service.login();
  218.       window.setTimeout(window.close, 1500);
  219.       this._status.value = this._str("change.password.status.success");
  220.     }
  221.     else if (this._currentBox.value != Weave.Service.password)
  222.       alert(this._str("incorrectPassword.alert"));
  223.     else {
  224.       this._status.value = this._str("change.password.status.active");
  225.  
  226.       if (Weave.Service.changePassword(this._firstBox.value))
  227.         this._status.value = this._str("change.password.status.success");
  228.       else
  229.         this._status.value = this._str("change.password.status.error");
  230.     }
  231.  
  232.     return false;
  233.   },
  234.   
  235.   _str: function Change__string(str) {
  236.     return this._stringBundle.getString(str);
  237.   }
  238. };
  239.  
  240. window.addEventListener("load", function(e) { Change.onLoad(); }, false);
  241. window.addEventListener("unload", function(e) { Change.shutDown(e); }, false);
  242.